<template>
  <el-row type="flex" style="width: 100%">
    <el-col> <i class="el-icon-user-solid myicon"></i>{{ data.name }}</el-col>
    <el-col :span="4">
      <el-row type="flex">
        <el-col class="fuze">{{ data.manager }}</el-col>
        <el-col>
          <el-dropdown @command="handlerCommand">
            <span class="el-dropdown-link">
              操作<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add">添加子部门</el-dropdown-item>
              <el-dropdown-item command="check">查看部门</el-dropdown-item>
              <el-dropdown-item command="del">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { removecompany } from "../../api/departments";
export default {
  props: ["data", "isRoot"],
  methods: {
    // 处理操作的下拉元素点击事件
    async handlerCommand(command) {
      // 判断
      if (command === "del") {
        // 删除操作
        try {
          // 询问是否删除
          // console.log(command);
          await this.$confirm("是否删除当前部门", "提示");
          // 提交数据到服务器
          await removecompany(this.data.id);
          // 添加提示信息
          this.$message.success("删除部门成功");
          // 更新数据：调用父组件中的方法
          this.$emit("updatedata");
        } catch {
          console.log("取消删除 & 删除出错");
        }
      } else if (command === "add") {
        // 打开新增面板
        this.$emit("opendialog", {
          data: this.data,
          process: "add",
        });
      } else {
        this.$emit("opendialog", {
          data: this.data,
          process: "eait",
        });
      }
    },
  },
};
</script>

<style lang='scss'>
.el-row {
  .fuze {
    text-align: right;
  }
}
</style>